﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using cbelo.Models;

namespace cbelo.Controllers
{
    public class ShopCartController : Controller
    {
        //
        // GET: /ShoppingCart/

        public ActionResult Index()
        {
            var cart = ShopCart.GetCart(this.HttpContext);

            return View(cart.GetCartItems());
        }

        //
        // GET: /Store/AddToCart/5

        public ActionResult AddToCart(int id, int type)
        {
            // Add it to the shopping cart
            var cart = ShopCart.GetCart(this.HttpContext);

            cart.AddToCart(id,type);

            // Go back to the main store page for more shopping
            return RedirectToAction("Index");
        }

        //
        // AJAX: /ShoppingCart/RemoveFromCart/5

        [HttpPost]
        public ActionResult RemoveFromCart(int id)
        {
            // Remove the item from the cart
            var cart = ShopCart.GetCart(this.HttpContext);

            /*
            // Get the name of the album to display confirmation
            string albumName = storeDB.Carts
                .Single(item => item.RecordId == id).Album.Title;

            // Remove from cart
            int itemCount = cart.RemoveFromCart(id);

            // Display the confirmation message
            var results = new ShoppingCartRemoveViewModel
            {
                Message = Server.HtmlEncode(albumName) +
                    " has been removed from your shopping cart.",
                CartTotal = cart.GetTotal(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,
                DeleteId = id
            };

            return Json(results);
            */
            return RedirectToAction("Index");
        }

        //
        // GET: /ShoppingCart/CartSummary

        [ChildActionOnly]
        public ActionResult CartSummary()
        {
            /*
            var cart = ShopCart.GetCart(this.HttpContext);

            ViewData["CartCount"] = cart.GetCount();

            return PartialView("CartSummary");
            */
            return RedirectToAction("Index");
        }

    }
}
